home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Miscellaneous / ival / dlog.c next >
Text File  |  1987-05-25  |  2KB  |  89 lines

  1. /*
  2.  * dlog.c - misc dialog item handling routines.
  3.  *
  4.  */
  5.  
  6. #include <memory.h>
  7. #include <quickdraw.h>
  8. #include <window.h>
  9. #include <event.h>
  10. #include <textedit.h>
  11. #include <dialog.h>
  12. #include <control.h>
  13. #include <toolutil.h>
  14. #include <resource.h>
  15.  
  16. /*
  17.  * radioswitch() - turn one radio button off & another one on,
  18.  *  returning the item ID of the new "on" button.
  19.  */
  20. int
  21. radioswitch(dlg, oncontrl, offcontrl)
  22. DialogPtr dlg;
  23. int oncontrl, offcontrl;    /* items to turn on and off, respectively */
  24. {
  25.     int itemtype;
  26.     ControlHandle item;
  27.     Rect itembox;
  28.  
  29.     GetDItem(dlg, offcontrl, &itemtype, &item, &itembox);
  30.     SetCtlVal(item, 0);
  31.     GetDItem(dlg, oncontrl, &itemtype, &item, &itembox);
  32.     SetCtlVal(item, 1);
  33.     return(oncontrl);
  34. }
  35.  
  36. /*
  37.  * radioset() - set one of a set of radio items, clearing the others.
  38.  */
  39.  
  40. radioset(dlg, onitem, firstitem, lastitem)
  41. DialogPtr dlg;
  42. short onitem;            /* item # of the item to turn on    */
  43.                 /*... == 0 means "turn everything off"    */
  44. short firstitem;        /* item # of the first item of the set    */
  45. short lastitem;            /* item # of the last item of the set    */
  46. {
  47.     short itemnum;    /* item # of the current item    */
  48.     short itemtype;
  49.     ControlHandle item;
  50.     Rect itembox;
  51.  
  52.     for (itemnum = firstitem; itemnum <= lastitem; ++itemnum) {
  53.     GetDItem(dlg, itemnum, &itemtype, &item, &itembox);
  54.     SetCtlVal(item, itemnum == onitem ? 1 : 0);
  55.     }
  56. }
  57.  
  58. /*
  59.  * justdigs() - restrict the contents of an EditText item to just the given
  60.  *  number of digits.  I.E., throw out non-digit characters & characters
  61.  *  beyond the end of the field.
  62.  * The field must be less than 100 characters wide.
  63.  */
  64.  
  65. justdigs(dlg, field, width)
  66. DialogPtr dlg;
  67. int field;        /* # of the dialog item to modify    */
  68. int width;        /* max # of digits in the field    */
  69. {
  70.     int itemtype;
  71.     ControlHandle item;
  72.     Rect itembox;
  73.     static char buf[100];
  74.     char *src, *dst;    /* pointers for removing non-digits    */
  75.  
  76.     GetDItem(dlg, field, &itemtype, &item, &itembox);
  77.     GetIText(item, buf);
  78.     ptoc(buf);
  79.     
  80.     dst = &buf[0];
  81.     for (src = &buf[0]; (*dst = *src); ++src) {
  82.         if (*dst >= 0 && *dst <= '9') ++dst;
  83.     }
  84.     buf[width] = '\0';
  85.  
  86.     ctop(buf);
  87.     SetIText(item, buf);
  88. }
  89.